<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>

  <input type="text" class="username"><br>
  <input type="text" class="password"><br>
  <input type="button" class="login" value="登录">

</body>
<script src="./js/ajax.js"></script>
<script>

$(".login").onclick = function(){
  ajax({
    method: "post",
    url:"http://localhost:3000/login",
    data:{
      username: $(".username").value,
      password: $(".password").value
    }
  }).then(res=>{
    res = JSON.parse(res);
    sessionStorage.setItem("token", res.token);
    console.log(res)
  })
}

function $(s){
  return document.querySelector(s)
}
  
</script>
</html>